{include="header"}

{if condition="$fsc->subcuenta"}
<script type="text/javascript">
   function fs_marcar_todo()
   {
      $('#f_subcuenta input:checkbox').prop('checked', true);
   }
   function fs_marcar_nada()
   {
      $('#f_subcuenta input:checkbox').prop('checked', false);
   }
   $("#b_eliminar").click(function(event) {
      event.preventDefault();
      if( confirm("¿Realmente desea eliminar esta subcuenta?") )
         window.location.href = '{$fsc->ppage->url()}&deletes={$fsc->subcuenta->idsubcuenta}';
   });
</script>

<form id="f_subcuenta" class="form" action="{$fsc->url()}&offset={$fsc->offset}" method="post">
   <input type="hidden" name="puntear" value="TRUE"/>
   
   <div class="table-responsive">
      <table class="table table-hover">
         <thead>
            <tr>
               <th class="text-left">Descripción</th>
               <th>Ejercicio</th>
               <th>Divisa</th>
               <th class="text-right">Debe</th>
               <th class="text-right">Haber</th>
               <th class="text-right">Saldo</th>
            </tr>
         </thead>
         <tr>
            <td>
               <input class="form-control" type="text" name="descripcion" value="{$fsc->subcuenta->descripcion}" autocomplete="off"/>
            </td>
            <td class="text-center">
               <div class="form-control">
                  <a href="{$fsc->ejercicio->url()}">{$fsc->ejercicio->nombre} ({$fsc->ejercicio->codejercicio})</a>
               </div>
            </td>
            <td>
               <select name="coddivisa" class="form-control">
               {loop="$fsc->divisa->all()"}
               <option value="{$value->coddivisa}"{if condition="$fsc->subcuenta->coddivisa==$value->coddivisa"} selected="selected"{/if}>{$value->descripcion}</option>
               {/loop}
               </select>
            </td>
            <td><div class="form-control text-right">{$fsc->show_precio($fsc->subcuenta->debe, $fsc->subcuenta->coddivisa)}</div></td>
            <td><div class="form-control text-right">{$fsc->show_precio($fsc->subcuenta->haber, $fsc->subcuenta->coddivisa)}</div></td>
            <td><div class="form-control text-right">{$fsc->show_precio($fsc->subcuenta->saldo, $fsc->subcuenta->coddivisa)}</div></td>
         </tr>
      </table>
   </div>
   
   <div class="container-fluid" style="margin-bottom: 10px;">
      <div class="row">
         <div class="col-lg-2 col-md-2 col-sm-2">
            <div class="btn-group">
               <button class="btn btn-sm btn-default" type="button" onclick="fs_marcar_todo()">
                  <span class="glyphicon glyphicon-check"></span>
               </button>
               <button class="btn btn-sm btn-default" type="button" onclick="fs_marcar_nada()">
                  <span class="glyphicon glyphicon-unchecked"></span>
               </button>
            </div>
         </div>
         <div class="col-lg-8 col-md-8 col-sm-8 text-center">
            <div class="btn-group">
            {loop="$fsc->paginas()"}
               <a class="btn btn-sm btn-default{if condition="$value.actual"} active{/if}" href="{$value.url}">{$value.num}</a>
            {/loop}
            </div>
         </div>
         <div class="col-lg-2 col-md-2 col-sm-2 text-right">
            <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled=true;this.form.submit();">
               <span class="glyphicon glyphicon-floppy-disk"></span>
               &nbsp; Guardar
            </button>
         </div>
      </div>
   </div>
   
   <div class="table-responsive">
      <table class="table table-hover">
         <thead>
            <tr>
               <th title="puntear">P</th>
               <th class="text-left">Asiento</th>
               <th>Fecha</th>
               <th class="text-left">Concepto</th>
               <th class="text-right">Debe</th>
               <th class="text-right">Haber</th>
               <th class="text-right">Saldo</th>
               <th class="text-right">IVA</th>
               <th class="text-right">Base imponible</th>
               <th>Contrapartida</th>
               <th>{#FS_CIFNIF#}</th>
            </tr>
         </thead>
         {$total=-1+count($fsc->resultados)}
         {loop="$fsc->resultados"}
         <tr>
            <td class="text-center">
               <input type="checkbox" name="punteada[]" value="{$value->idpartida}"{if condition="$value->punteada"} checked="checked"{/if}/>
            </td>
            <td><a href="{$value->url()}">{$value->numero}</a></td>
            <td class="text-center">{$value->fecha}</td>
            <td><a href="{$value->url()}">{$value->concepto}</a></td>
            <td class="text-right">{$fsc->show_precio($value->debe, $fsc->subcuenta->coddivisa)}</td>
            <td class="text-right">{$fsc->show_precio($value->haber, $fsc->subcuenta->coddivisa)}</td>
            <td class="text-right">{$fsc->show_precio($value->saldo, $fsc->subcuenta->coddivisa)}</td>
            <td class="text-right">
               {if condition="$value->iva!=0"}{$value->iva} %{else}-{/if}
            </td>
            <td class="text-right">
               {if condition="$value->baseimponible!=0"}{$fsc->show_precio($value->baseimponible, $fsc->subcuenta->coddivisa)}{else}-{/if}
            </td>
            <td class="text-center">
               {if condition="$value->codcontrapartida"}
               <a href="{$value->contrapartida_url()}">{$value->codcontrapartida}</a>
               {else}
               -
               {/if}
            </td>
            <td class="text-center">
               {if condition="$value->cifnif"}{$value->cifnif}{else}-{/if}
            </td>
         </tr>
         {if condition="$counter==$total"}
         <tr>
            <td colspan="4" class="text-right"><b>Sumas</b>:</td>
            <td class="text-right"><b>{$fsc->show_precio($value->sum_debe, $fsc->subcuenta->coddivisa)}</b></td>
            <td class="text-right"><b>{$fsc->show_precio($value->sum_haber, $fsc->subcuenta->coddivisa)}</b></td>
            <td colspan="5"></td>
         </tr>
         {/if}
         {/loop}
         <tr>
            <td colspan="11" class="text-center">
               <a class="btn btn-sm btn-block btn-success" href="index.php?page=contabilidad_nuevo_asiento">Nuevo Asiento...</a>
            </td>
         </tr>
      </table>
   </div>
   
   {if condition="$total>10"}
   <div class="container-fluid">
      <div class="row">
         <div class="col-lg-2 col-md-2 col-sm-2">
            <div class="btn-group">
               <button class="btn btn-sm btn-default" type="button" onclick="fs_marcar_todo()">
                  <span class="glyphicon glyphicon-check"></span>
               </button>
               <button class="btn btn-sm btn-default" type="button" onclick="fs_marcar_nada()">
                  <span class="glyphicon glyphicon-unchecked"></span>
               </button>
            </div>
         </div>
         <div class="col-lg-8 col-md-8 col-sm-8 text-center">
            <div class="btn-group">
            {loop="$fsc->paginas()"}
               <a class="btn btn-sm btn-default{if condition="$value.actual"} active{/if}" href="{$value.url}">{$value.num}</a>
            {/loop}
            </div>
         </div>
         <div class="col-lg-2 col-md-2 col-sm-2 text-right">
            <button class="btn btn-sm btn-primary" type="submit" onclick="this.disabled=true;this.form.submit();">
               <span class="glyphicon glyphicon-floppy-disk"></span>
               &nbsp; Guardar
            </button>
         </div>
      </div>
   </div>
   {/if}
</form>
{else}
<div class="text-center">
   <img src="view/img/fuuu_face.png" alt="fuuuuu"/>
</div>
{/if}

{include="footer"}
